package com.ruoyi.youtian.service.impl;

import com.ruoyi.gzmx_tag.domain.Gzmx_tag;
import com.ruoyi.gzmx_tag.mapper.Gzmx_tagMapper;
import com.ruoyi.youtian.domain.PointAttribute;
import com.ruoyi.youtian.domain.PointEquipment;
import com.ruoyi.youtian.domain.PointEquipmentVo2;
import com.ruoyi.youtian.mapper.PointAttributeMapper;
import com.ruoyi.youtian.mapper.PointEquipmentMapper;
import com.ruoyi.youtian.service.IScdwDeviceService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author bl
 */
@Service
public class IScdwDeviceServiceImpl implements IScdwDeviceService {



    @Autowired
    private PointAttributeMapper pointAttributeMapper;

    @Autowired
    private PointEquipmentMapper pointEquipmentMapper;

    @Autowired
    private Gzmx_tagMapper gzmxTagMapper;

    @Override
    public int scdwDeviceBound(PointEquipmentVo2 pointEquipmentVo) {
        // 设备点位关系表新增
        PointEquipment pointEquipment = new PointEquipment();
        BeanUtils.copyProperties(pointEquipment, pointEquipmentVo);
        pointEquipmentMapper.insertPointEquipment(pointEquipment);
        // 采集点位安装属性更新
        Gzmx_tag  tag = new Gzmx_tag();
        tag.setSourceTag(pointEquipmentVo.getPointId());
        tag.setEjdw_id(1l);
//        tag.setEjdw_name("");
//        tag.setDw_3_id();
//        tag.setDw_3_name();
//        tag.setDw_4_id();
//        tag.setDw_4_name();
//        tag.setDw_5_id();
//        tag.setDw_5_name();
        gzmxTagMapper.updateGzmx_tag(tag);

        // 点位表属性新增
        PointAttribute pointAttribute = new PointAttribute();
        pointAttribute.setPointId(pointEquipmentVo.getPointId());
        pointAttribute.setSceneId(-1L);
        pointAttribute.setUpperLimit(pointEquipmentVo.getMaximum());
        pointAttribute.setLowerLimit(pointEquipmentVo.getMinimum());
        return pointAttributeMapper.insertPointAttribute(pointAttribute);
    }

    @Override
    public int scdwDeviceunBound(PointEquipmentVo2 pointEquipmentVo) {
        // 删除关系
        PointEquipment pointEquipment = new PointEquipment();
        BeanUtils.copyProperties(pointEquipment, pointEquipmentVo);
        pointEquipmentMapper.detetePointEquipmentByPointEquipment(pointEquipment);

        // 采集点位安装属性更新
        Gzmx_tag  tag = new Gzmx_tag();
        tag.setSourceTag(pointEquipmentVo.getPointId());
        tag.setEjdw_id(1l);
//        tag.setEjdw_name("");
//        tag.setDw_3_id();
//        tag.setDw_3_name();
//        tag.setDw_4_id();
//        tag.setDw_4_name();
//        tag.setDw_5_id();
//        tag.setDw_5_name();
        gzmxTagMapper.updateGzmx_tag(tag);
        PointAttribute pointAttribute = new PointAttribute();
        pointAttribute.setPointId(pointEquipmentVo.getPointId());
        pointAttribute.setSceneId(0L);
        pointAttributeMapper.deletePointAttributeByPointAttribute(pointAttribute);
        return 0;
    }
}
